﻿@using Model;
@{
    Layout = "~/Admin/_AdminSiteLayout.cshtml";
    Page.Title = "Dashboard";

    List<SelectListItem> listItem = new List<SelectListItem>();

    List<Question> questions = SiteHelper.GetAllQuestions();
    List<Question> questionList = new List<Question>();
    foreach (Question item in questions)
    {
        if (string.IsNullOrEmpty(item.AnswerStatus))
        {
            //questions.Remove(item);

            item.AnswerStatus = SiteHelper.GetStatus(item.IsAnswered);

            questionList.Add(item);
        }
    }
    questions = questionList;

    int unAnsweredQuestion = questions.Count(x => x.IsAnswered == 0);
    int failedAnswer = questions.Count(x => x.IsAnswered == 1);
    int rightAnswer = questions.Count(x => x.IsAnswered == 2);
    int wrongAnswer = questions.Count(x => x.IsAnswered == 3);

    Question champs = questions.FirstOrDefault(x => x.Results == questions.Max(p => p.Results));
}
@{
    var grid = new WebGrid(source: questions, rowsPerPage: WebSite.RowsPerPage);
    <fieldset>
        <legend>Dashboard</legend>
        <div id="grid">
            @grid.GetHtml(
                tableStyle: "gridTable",
                headerStyle: "gridTableHeader",
                rowStyle: "rowstyle",
                alternatingRowStyle: "alternaterowstyle",
                columns: grid.Columns(
                grid.Column("Questions", "Questions"),
                grid.Column("TotalAnsweringTime", "Total Answering Time", style: "text-align-center"),
                                  grid.Column("AnswerStatus", "Is Answered", style: "text-align-center AnswerStatus"),
                grid.Column("ReadingClass", "Reading Class", style: "text-align-center"),
                grid.Column("Results", format: @<span>@item.Results.ToString("N")</span>, style: "text-align-center"),
                grid.Column("UserId", "Answer By", format: @<a href=@Href("~/Account/ViewProfile/" + @item.UserId)>
                    <img src="../Images/ico-profile.png" alt="Details" /></a>, style: "text-align-center"),
                grid.Column("Details", "", format: @<a href="QuestionDetails/@item.Id">
                    <img src="../Images/ico-view-detailed.png" alt="Details" /></a>, style: "text-align-center"),
                grid.Column("Delete", "", format: @<a href="DeleteQuestion/@item.Id">
                    <img src="../Images/ico-delete.png" alt="Delete" /></a>, style: "text-align-center")
            )
            )
        </div>
        <div class="result-status">
            <span>Total Question: @questions.Count
            </span><span>Total Unanswered Question : @unAnsweredQuestion
            </span><span class="RightAnswered">Right Answer :
                @rightAnswer
            </span><span class="WrongAnswered">Wrong Answer : @wrongAnswer
            </span><span class="NotAnswered">Not Answered : @failedAnswer
            </span><span>Champion Score : @champs.Results
            </span>
            @{
                string profileLink = "~/Account/ViewProfile/" + champs.UserId;
            }
            <a class="button thin green"href= "@Href(profileLink)">View Champion's Profile</a>
        </div>
    </fieldset>
}
<script src="@Href("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>
<script src="@Href("~/Scripts/Answer-table-color.js")" type="text/javascript"></script>